<template>
<div>
<!--  提示-->
 <div>
   <el-breadcrumb separator-class="el-icon-arrow-right">
     <el-breadcrumb-item>您正在做的业务是:</el-breadcrumb-item>
     <el-breadcrumb-item>用户管理</el-breadcrumb-item>
     <el-breadcrumb-item>新建用户</el-breadcrumb-item>
   </el-breadcrumb>
 </div>

<!--  表单添加-->
  <div>

    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名:">
        <el-input v-model="form.loginId"></el-input>
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item label="邮箱:">
        <el-input v-model="form.email"></el-input>
        <el-button type="primary" @click="sendTheVerificationCode">发送验证码</el-button>
      </el-form-item>

      <el-form-item label="验证码:">
        <el-input v-model="verificationCode"></el-input>
      </el-form-item>
      <el-form-item label="性别:">
        <el-radio v-model="form.gender" label="0">男</el-radio>
        <el-radio v-model="form.gender" label="1">女</el-radio>
      </el-form-item>

      <el-form-item label="地址:">
        <el-input v-model="form.address"></el-input>
      </el-form-item>

      <el-form-item label="电话:">
        <el-input v-model="form.phone"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="info">取消</el-button>
        <el-button type="primary" @click="add">添加</el-button>
      </el-form-item>
    </el-form>
  </div>
</div>
</template>

<script>
import axios from "axios";
import request from "../../request.js"

export default {
name: "userAdd",
  data(){
  return{
    form:{
      loginId:'',
      password:'',
      email:'',
      gender:'',
      address:'',
      phone:'',
    },
    //验证码
    verificationCode:''
  }
  },methods:{

  //发送验证码
  sendTheVerificationCode(){

    axios.get("http://localhost:8150/api/ucenter/wx/email/"+this.form.email).then(data =>{
      this.$message({
        showClose:true,
        message:data.data.message,
        type:data.data.flag==true?"success":"error"
      });
    }).catch(e =>{
      alert("错误信息为:"+e)
    })
  },
    add(){
      let map={
        'message':this.verificationCode,
        'users':this.form
      }
      axios.post("http://localhost:8150/api/ucenter/wx/",map).then(data =>{
        if (data.data.flag==false) {
          this.$message({
            showClose: true,
            message: data.data.message,
            type: data.data.flag == true ? "success" : "error"
          })
          return;
        }
        if (data.data.flag){
          this.form={};
          this.verificationCode="";
        }
        this.$message({
          showClose:true,
          message:data.data.message,
          type:data.data.flag==true?"success":"error"
        });
      }).catch(e =>{
        alert("错误信息为:"+e)
      })
    }
  }

}
</script>

<style scoped>

</style>